package com.skycong.hello77.datepicker.adapter;


import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.skycong.hello77.R;
import com.skycong.hello77.datepicker.entity.OwnTypeSelect;

import java.util.List;

/**
 * Created by Kiki on 2018/6/21.
 */

public class TopAndBottomPopAdapter extends BaseAdapter {
    private Context context;
    private List<OwnTypeSelect> dataList;

    public TopAndBottomPopAdapter(Context context, List<OwnTypeSelect> dataList){
        this.context = context;
        this.dataList = dataList;
    }


    @Override
    public int getCount() {
        return dataList.size();
    }

    @Override
    public Object getItem(int position) {
        return dataList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        OwnTypeSelectView itemView;
        if(convertView == null){
            convertView = View.inflate(parent.getContext(),R.layout.pop_window_item,null) ;
            itemView = new OwnTypeSelectView(convertView);
            convertView.setTag(itemView);
        }else{
            itemView = (OwnTypeSelectView) convertView.getTag();
        }
        itemView.setMessage(dataList.get(position));

        return convertView;
    }

    public class OwnTypeSelectView{
        public TextView tv_class_name;
        public ImageView img_select;
        public View view_line;

       public OwnTypeSelectView(View view){
           tv_class_name = (TextView) view.findViewById(R.id.tv_class_name);
           img_select = (ImageView) view.findViewById(R.id.img_select);
           view_line = view.findViewById(R.id.view_line);
       }
       public void setMessage(OwnTypeSelect data){
           tv_class_name.setText(data.name);
           if (data.isDefault) {
               tv_class_name.setTextColor(context.getResources().getColor(R.color.text_orange));
               img_select.setVisibility(View.VISIBLE);
               view_line.setBackgroundColor(context.getResources().getColor(R.color.text_orange));
           }else {
               tv_class_name.setTextColor(context.getResources().getColor(R.color.line_gray));
               img_select.setVisibility(View.GONE);
               view_line.setBackgroundColor(context.getResources().getColor(R.color.line_gray));
           }
       }

    }
}
